package com.qut.servlet;

import java.io.IOException;
import java.util.*;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.qut.service.DocInfoService;

@WebServlet("/DocLoginServlet")
public class DocLoginServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       

    public DocLoginServlet() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		request.setCharacterEncoding("UTF-8");
		Map<String, String[]> params=request.getParameterMap();
		DocInfoService service=new DocInfoService();
		Map<String,String> map=service.checkLogin(params);
		if(map!=null){
			HttpSession session=request.getSession();
			session.setAttribute("doc", map);
			response.sendRedirect("Nav.html");
		}else{
			response.sendRedirect("error.jsp");
		}
	}

}
